<?php
class ManageProductHotForm extends Form{
	function ManageProductHotForm(){
		Form::Form('ManageProductHotForm');
	}

	function draw(){
		global $display;
		$cmd=Url::get('cmd');
		if ($cmd == 'update'){
			AZMemcache::do_put("prhot_ver:",0);
			Url::redirect_current();
		}
		$this->beginForm();

		$list_cat = array (999999999=>'Mặc định',0=>'Trang chủ');
		$list_cat += AZLib::getTopCats();

		$item = DB::fetch_all('SELECT item_id,status,product_hot_cat_id,end_time,start_time FROM product_hot');
		$items_tmp=array();
		foreach ($item as $values){
			if (isset($list_cat[$values['product_hot_cat_id']])){
				$items_tmp[$values['product_hot_cat_id']]['cat_name'] = $list_cat[$values['product_hot_cat_id']];
				if($values['status'] == 1){
					$items_tmp[$values['product_hot_cat_id']]['item_vip'][$values['item_id']]['cat_id'] = $values['product_hot_cat_id'];
					$items_tmp[$values['product_hot_cat_id']]['item_vip'][$values['item_id']]['start_time'] = date("d/m/Y",$values['start_time']);
					$items_tmp[$values['product_hot_cat_id']]['item_vip'][$values['item_id']]['end_time'] = date("d/m/Y",$values['end_time']);
				}
				else{
					$items_tmp[$values['product_hot_cat_id']]['item'][$values['item_id']] = $values['product_hot_cat_id'];
				}
			}
		}
		$items=array();
		foreach ($list_cat as $key=>$values){
			if (isset($items_tmp[$key])){
				$items[$key] = $items_tmp[$key];
			}
		}

		$display->add('items',$items);
		$display->output('ManageProductHot');
		$this->endForm();
	}


}
?>